﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// autoCAD Header
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace _02AddEntityTools
{
    public class ArcExam
    {
        [CommandMethod("ArcExam")]
        public void arcDemo()
        {
            Arc arc1 = new Arc();
            arc1.Center = new Point3d(10, 10, 0);
            arc1.Radius = 10;
            arc1.StartAngle = -Math.PI / 4;
            arc1.EndAngle = Math.PI / 4;

            double startAngle = 45;
            double endAngle = 90;
            Arc arc2 = new Arc(new Point3d(20, 20, 0), 10, startAngle.angleTodegree(), endAngle.angleTodegree());

            Arc arc3 = new Arc(new Point3d(30, 30, 0), new Vector3d(0, 0, 1), 15, Math.PI / 10, Math.PI / 20);

            Database database= HostApplicationServices.WorkingDatabase;
            database.addEntityToModelSpace(arc1, arc2, arc3);
            database.addArcToModelSpace(new Point3d(50, 50, 0), 30, 0, 270);

        }

        [CommandMethod("cArcExam")]
        public void cArcDemo()
        {
            CircularArc3d cArc0 = new CircularArc3d(new Point3d(100, 200, 0),
                new Point3d(150, 300, 0),
                new Point3d(300, 250, 0));

            Point3d starpoint=new Point3d(100,100,0);
            Point3d endpoint = new Point3d(200, 200, 0);
            Point3d onArcpoint = new Point3d(150, 170, 0);

            CircularArc3d cArc1 = new CircularArc3d(new Point3d(100, 200, 0),
                new Point3d(150, 300, 0),
                new Point3d(300, 250, 0));

            double radius = cArc1.Radius;
            Point3d center = cArc1.Center;

            double StartAngle = cArc1.StartAngle;
            double EndAngle = cArc1.EndAngle;
            Arc arc1 = new Arc(center, radius, StartAngle, EndAngle);

            Vector3d sc = starpoint.GetVectorTo(center);
            Vector3d ec = endpoint.GetVectorTo(center);

            Vector3d cs = center.GetVectorTo(starpoint);
            Vector3d ce = center.GetVectorTo(endpoint);
            Vector3d xvector = new Vector3d(1, 0, 0);   //X 轴方向

            double startAngle = xvector.GetAngleTo(cs);
            double endAngle = xvector.GetAngleTo(ce);
            Arc arc2=new Arc(center, radius, startAngle, endAngle);


            double startAngleNew = cs.Y > 0 ? xvector.GetAngleTo(cs) : -xvector.GetAngleTo(cs);
            double endAngleNew = ce.Y > 0 ? xvector.GetAngleTo(ce) : -xvector.GetAngleTo(ce);
            Arc arc3 = new Arc(center, radius, startAngleNew, endAngleNew);


            Database database = HostApplicationServices.WorkingDatabase;
            database.addEntityToModelSpace(arc1);
        }
    }
}
